### Lippert et al. - People's attitudes and emotions towards different urban forest types in the Berlin region, Germany ###  


### Attitudes towards nature types ###

SurveyDaten <- read.csv2("Data_Set.csv")

str(SurveyDaten)

Attitudes <- SurveyDaten[c(6:8,13:15,20:22,27:29)]
AttNatur1 <- Attitudes[c(1:3)]
AttNatur2 <- Attitudes[c(4:6)]
AttNatur3 <- Attitudes[c(7:9)]
AttNatur4 <- Attitudes[c(10:12)]

# Cronbach�s alpha:

library(psych) 

alpha(AttNatur1, keys=NULL, max=10,na.rm = TRUE,
      check.keys=TRUE,n.iter=1,delete=TRUE,use="pairwise",warnings=TRUE,n.obs=NULL)


alpha(AttNatur2, keys=NULL, max=10,na.rm = TRUE,
      check.keys=TRUE,n.iter=1,delete=TRUE,use="pairwise",warnings=TRUE,n.obs=NULL)


alpha(AttNatur3, keys=NULL, max=10,na.rm = TRUE,
      check.keys=TRUE,n.iter=1,delete=TRUE,use="pairwise",warnings=TRUE,n.obs=NULL)

alpha(AttNatur4, keys=NULL, max=10,na.rm = TRUE,
      check.keys=TRUE,n.iter=1,delete=TRUE,use="pairwise",warnings=TRUE,n.obs=NULL)

# Mean values:

SurveyDaten$Attitudes_Nature_1 <- rowMeans(AttNatur1[,c(1:3)], na.rm=TRUE)
SurveyDaten$Attitudes_Nature_2 <- rowMeans(AttNatur2[,c(1:3)], na.rm=TRUE)
SurveyDaten$Attitudes_Nature_3 <- rowMeans(AttNatur3[,c(1:3)], na.rm=TRUE)
SurveyDaten$Attitudes_Nature_4 <- rowMeans(AttNatur4[,c(1:3)], na.rm=TRUE)

AttAll <- cbind(SurveyDaten$Attitudes_Nature_1,SurveyDaten$Attitudes_Nature_2,SurveyDaten$Attitudes_Nature_3,SurveyDaten$Attitudes_Nature_4)

mean(SurveyDaten$Attitudes_Nature_1)
mean(SurveyDaten$Attitudes_Nature_2)
mean(SurveyDaten$Attitudes_Nature_3)
mean(SurveyDaten$Attitudes_Nature_4)

sd(SurveyDaten$Attitudes_Nature_1)
sd(SurveyDaten$Attitudes_Nature_2)
sd(SurveyDaten$Attitudes_Nature_3)
sd(SurveyDaten$Attitudes_Nature_4)
        
# pairwise comparison:

TabNew <- read.csv2("Data_Set_1_AttMean.csv")
str(TabNew)
attach(TabNew)

kruskal.test(MeanAttitudes~Nature, data = TabNew)

pairwise.wilcox.test(MeanAttitudes,Nature, paired = TRUE, p.adj="bonferroni")

library(psych)
describeBy(MeanAttitudes,Nature)

detach(TabNew)

boxplot(AttAll, col.lab="black", col=(c("palegreen2", col="lightskyblue2", col="peachpuff2", col="indianred2")), 
        las=1,names = c("1","2","3","4"), font=2)




### emotions towards nature types ###

EmotionNature1 <- SurveyDaten [,2:5]
EmotionNature2 <- SurveyDaten [,9:12] 
EmotionNature3 <- SurveyDaten [,16:19] 
EmotionNature4 <- SurveyDaten [,23:26] 

# Cronbach�s alpha:

library(psych)

alpha(EmotionNature1, keys=NULL, max=10,na.rm = TRUE,
      check.keys=TRUE,n.iter=1,delete=TRUE,use="pairwise",warnings=TRUE,n.obs=NULL)

alpha(EmotionNature2, keys=NULL, max=10,na.rm = TRUE,
      check.keys=TRUE,n.iter=1,delete=TRUE,use="pairwise",warnings=TRUE,n.obs=NULL)

alpha(EmotionNature3, keys=NULL, max=10,na.rm = TRUE,
      check.keys=TRUE,n.iter=1,delete=TRUE,use="pairwise",warnings=TRUE,n.obs=NULL)

alpha(EmotionNature4, keys=NULL, max=10,na.rm = TRUE,
      check.keys=TRUE,n.iter=1,delete=TRUE,use="pairwise",warnings=TRUE,n.obs=NULL)

# Mean values:

SurveyDaten$Emotions_Nature_1 <- rowMeans(EmotionNature1[,c(1:4)], na.rm=TRUE)
SurveyDaten$Emotions_Nature_2 <- rowMeans(EmotionNature2[,c(1:4)], na.rm=TRUE)
SurveyDaten$Emotions_Nature_3 <- rowMeans(EmotionNature3[,c(1:4)], na.rm=TRUE)
SurveyDaten$Emotions_Nature_4 <- rowMeans(EmotionNature4[,c(1:4)], na.rm=TRUE)

EmotionenAll <- cbind(SurveyDaten$Emotions_Nature_1,SurveyDaten$Emotions_Nature_2,SurveyDaten$Emotions_Nature_3,SurveyDaten$Emotions_Nature_4)
summary(EmotionenAll)

mean(SurveyDaten$Emotions_Nature_1)
mean(SurveyDaten$Emotions_Nature_2)
mean(SurveyDaten$Emotions_Nature_3)
mean(SurveyDaten$Emotions_Nature_4)

sd(SurveyDaten$Emotions_Nature_1)
sd(SurveyDaten$Emotions_Nature_2)
sd(SurveyDaten$Emotions_Nature_3)
sd(SurveyDaten$Emotions_Nature_4)

# pairwise comparison:

Tab2New <- read.csv2("Data_Set_1_EmotionMean.csv")
str(Tab2New)
attach(Tab2New)

kruskal.test(MeanEmotion~Naturetype, data = Tab2New)

pairwise.wilcox.test(Tab2New$MeanEmotion,Tab2New$Naturetype, paired = TRUE, p.adj="bonferroni")

library(psych)
describeBy(MeanEmotion,Naturetype)

detach(Tab2New)


boxplot(EmotionenAll, col.lab="black", col=(c("palegreen2", col="lightskyblue2", col="peachpuff2", col="indianred2")), las=1, 
        names = c("1","2","3","4"),
        font=2)




### predictive potential of socio-demographic factors ###

# age:
AlterCut <- cut(SurveyDaten$Alter.1, breaks=c(0, 30, 45, 60, Inf), labels=c("19-30", "31-45", "46-61", ">61"))
SurveyDaten <- cbind(SurveyDaten,AlterCut)

# gender:
SurveyDaten$Geschlecht <- as.factor(SurveyDaten$Geschlecht)

# place of growing up:
SurveyDaten$Wohnort.Kindheit <- as.factor(SurveyDaten$Wohnort.Kindheit)

# place attachment:
Place <- SurveyDaten [,30:32]
library(psych)
alpha(Place, keys=NULL, max=10,na.rm = TRUE,
      check.keys=TRUE,n.iter=1,delete=TRUE,use="pairwise",warnings=TRUE,n.obs=NULL) 
SurveyDaten$PlaceMean <- rowMeans(SurveyDaten[,c(30:32)], na.rm=TRUE)


## on attitudes: ##

names(SurveyDaten)

attitudes1 <- glm(SurveyDaten$Attitudes_Nature_1 ~ SurveyDaten$AlterCut+
                    SurveyDaten$Geschlecht+SurveyDaten$Wohnort.Kindheit+
                    SurveyDaten$PlaceMean, data = SurveyDaten)
summary(attitudes1)

attitudes2 <- glm(SurveyDaten$Attitudes_Nature_2 ~ SurveyDaten$AlterCut+
                    SurveyDaten$Geschlecht+SurveyDaten$Wohnort.Kindheit+
                    SurveyDaten$PlaceMean, data = SurveyDaten)
summary(attitudes2)

attitudes3 <- glm(SurveyDaten$Attitudes_Nature_3 ~ SurveyDaten$AlterCut+
                    SurveyDaten$Geschlecht+SurveyDaten$Wohnort.Kindheit+
                    SurveyDaten$PlaceMean, data = SurveyDaten)
summary(attitudes3)

attitudes4 <- glm(SurveyDaten$Attitudes_Nature_4 ~ SurveyDaten$AlterCut+
                    SurveyDaten$Geschlecht+SurveyDaten$Wohnort.Kindheit+
                    SurveyDaten$PlaceMean, data = SurveyDaten)
summary(attitudes4)

## on emotions: ##

emotions1 <- glm(SurveyDaten$Emotions_Nature_1 ~ SurveyDaten$AlterCut+
                   SurveyDaten$Geschlecht+SurveyDaten$Wohnort.Kindheit+
                   SurveyDaten$PlaceMean, data = SurveyDaten)
summary(emotions1)

emotions2 <- glm(SurveyDaten$Emotions_Nature_2 ~ SurveyDaten$AlterCut+
                   SurveyDaten$Geschlecht+SurveyDaten$Wohnort.Kindheit+
                   SurveyDaten$PlaceMean, data = SurveyDaten)
summary(emotions2)

emotions3 <- glm(SurveyDaten$Emotions_Nature_3 ~ SurveyDaten$AlterCut+
                   SurveyDaten$Geschlecht+SurveyDaten$Wohnort.Kindheit+
                   SurveyDaten$PlaceMean, data = SurveyDaten)
summary(emotions3)

emotions4 <- glm(SurveyDaten$Emotions_Nature_4 ~ SurveyDaten$AlterCut+
                   SurveyDaten$Geschlecht+SurveyDaten$Wohnort.Kindheit+
                   SurveyDaten$PlaceMean, data = SurveyDaten)
summary(emotions4)